package artid.com.arttogo.activity;

import java.util.ArrayList;
import java.util.List;
import com.android.volley.VolleyError;
import android.media.Image;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import artid.com.arttogo.R;
import artid.com.arttogo.adapter.MallDetFragmentAdapter;
import artid.com.arttogo.app.ArtToGoApp;
import artid.com.arttogo.bean.GoodsList;
import artid.com.arttogo.bean.ShareItem;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.view.SubViewPager;

/**
 * 艺术商城-商品详情基类
 */
public class MallDetailPagerActivity extends BaseActivity implements OnClickListener{

    public static SubViewPager mViewPager;
    MallDetFragmentAdapter adapter;
    ImageView ivShare;
    ShareItem shareitem;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        mContext = MallDetailPagerActivity.this;
        setContentView(R.layout.activity_malldet_pager);
        ArtToGoApp.getInstance().addMallActivity(MallDetailPagerActivity.this);
        mViewPager = (SubViewPager)findViewById(R.id.viewPager);
        mTittle = (TextView)findViewById(R.id.tittle_text);
        mTittle.setText("商品详情");
        mBack = (ImageView)findViewById(R.id.back_btn);
        mBack.setOnClickListener(this);
        ivShare = (ImageView)findViewById(R.id.share_detail);
        ivShare.setOnClickListener(this);
        adapter = new MallDetFragmentAdapter(getSupportFragmentManager());

        String json = getIntent().getExtras().getString("id");

        VolleyData vd = new VolleyData(json, GoodsList.class);
        List<GoodsList> mList = (List<GoodsList>)vd.getList();
        adapter.setData(mList);
        adapter.notifyDataSetChanged();

        int index = 0;
        index = getIntent().getExtras().getInt("index");
        mViewPager.setAdapter(adapter);
        mViewPager.setOffscreenPageLimit(2);
        mViewPager.setOnPageChangeListener(mOnPageChangeListener);
        mViewPager.setCurrentItem(index);
    }

    int index = 0;
    private OnPageChangeListener mOnPageChangeListener = new OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            index = position;
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        @Override
        public void onPageScrollStateChanged(int arg0) {

        }
    };

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch (arg0.getId()) {
            case R.id.back_btn:
                finish();
                break;
//		case R.id.share_detail:

//			shareitem =  adapter.getShareitem(index);
//			if (shareitem == null) {
//				Config.showTip(MallDetailPagerActivity.this, "请检查网络连接");
//			}
//			AppUtil.showShare(mContext, shareitem.getTitle(), shareitem.getContent(),
//					shareitem.getImageUrl(), shareitem.getUrl(),shareitem.getUid() ,
//					shareitem.getHeadUrl(), shareitem.getContent());
//			AppUtil.shareWithTalk(mContext, shareitem.getTitle(), shareitem.getContent(), shareitem.getImageUrl(), shareitem.getUrl(), shareitem.getUid(), shareitem.getHeadUrl(),shareitem.getAname());
//			break;
            default:
                break;
        }
    }
}
